<?php

/**
 * 自动生成 WxEventShakeController
 * 
 * Apps/Mp/Controller/WxEventShakeController.class.php
 * Zix @ 2015-09-03
 */

namespace Mp\Controller;

use Common\Service\WxEventShakeService;

class WxEventShakeController extends MpController {

  public function index( $wx_id ) {
    $action = I('get.action', 'read');

    $data = $this->_init_data();
    $data['module_name'] = '摇一摇';
    $data['module_url'] = U($this->base_path . 'index');

    $WxEventShake = WxEventShakeService::instance();
    $data['config'] = array(
      'action' => $action,
      'action_label' => $this->action_label[$action],
      'menu_id' => 'menu_Mp_MerWxSetting_index',
      'wx_id' => $wx_id ,
      'mer_id' => $this->mer_id ,
      'module_url' => U($this->base_path . 'index'),
      'read_url' => U($this->base_path . 'read'). "/$wx_id",
      'create_url' => U($this->base_path . 'create'). "/$wx_id",
      'update_url' => U($this->base_path . 'update'),
      'delete_url' => U($this->base_path . 'delete'),
      'upload_icon_url' => U($this->base_path . 'upload') .'/icon',
      'del_icon_url' => U($this->base_path . 'delete_icon') ,
      'user_url' => U( 'Mp/WxEventShakeUser/index' ) . '/' ,
      'award_url' => U( 'Mp/WxEventShakeAward/index' ) . '/' ,
      'page' => 1,
      'page_size' => C('PAGE_SIZE'),
      'row' => $WxEventShake->get_default_row()
    );

    $data['param'] = array();

    $this->display_with_layout($data, $this->controller . ':index');
  }

  function read( $wx_id ) {
    $post = I('post.');

    $config = array(
      'wx_id' => $wx_id ,
      'page' => $post['page'],
      'page_size' => $post['page_size'],
      'sort' => empty($post['sort']) ? 'id' : $post['sort'],
      'order' => empty($post['order']) ? 'DESC' : $post['order'],
    );

    $WxEventShake = WxEventShakeService::instance();
    $data['rows'] = $WxEventShake->get_by_cond($config);

    $config['count'] = TRUE;
    $data['total'] = $WxEventShake->get_by_cond($config);

    $this->ajaxReturn($data);
  }

  function create( $wx_id ) {
    $post = I('post.');
    if (empty($post)) {
      $this->ajaxReturn(ajax_arr('数据错误,请稍后再试'));
    }
    $post['mer_id'] = $this->mer_id ;
    $post['wx_id'] = $wx_id ;
    $WxEventShake = WxEventShakeService::instance();
    $ret = $WxEventShake->create($post);
    $this->ajaxReturn($ret);
  }

  function update($id = 0) {
    $post = I('post.');
    if (empty($post)) {
      $this->ajaxReturn(ajax_arr('数据错误,请稍后再试'));
    }

    $WxEventShake = WxEventShakeService::instance();
    $ret = $WxEventShake->update($id, $post);
    $this->ajaxReturn($ret);
  }

  function delete() {
    $ids = I('post.ids');
    $WxEventShake = WxEventShakeService::instance();
    $ret = $WxEventShake->delete($ids);
    $this->ajaxReturn($ret);
  }

  function read_test() {
    $WechatPay = new \Common\Service\WechatPayService( 1 , 26 );
    
    
    $WechatPay->send_redpack($openid, $amount);
  }
}
